package 滑动窗口;

/**
 * @Author: biubiu0002
 * @Date: 2021-09-06 10:31
 **/
public class 无重复字符的最长子串 {
    public static void main(String[] args) {
        String s = "qrsvbspk";
        System.out.println(lengthOfLongestSubstring(s));

    }

    public static int lengthOfLongestSubstring(String s) {
        //index为字符的ASCII码 存放每个字符在s中最后出现的index
        int[] last = new int[128];
        for (int i = 0; i < last.length; i++) {
            last[i]=-1;
        }

        int n = s.length();
        int start =0;
        int max=0;
        for(int i=0;i<n;i++){
            int index = s.charAt(i);
            start = Math.max(last[index],start);
            max = Math.max(i-start,max);
            last[index] = i;
        }
        return max;


    }
}
